package com.woniuxy.openfeign.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 获取网页信息工具类
 */

public class WebUtil {
    /**
     * 获取请求
     * @return 请求信息
     */
    public static HttpServletRequest getRequest(){
        try {
            ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            return sra.getRequest();
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 后期响应信息
     * @return 响应信息
     */
    public static HttpServletResponse getResponse(){
        try {
            ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            return sra.getResponse();
        } catch (Exception e) {
            return null;
        }
    }
}
